package web.suzy.oj.controller.file;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.service.file.ImageService;

import java.util.Map;

/**
 * YangSuzy 软件工作室
 * 类名: ImageController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/30 11:31
 */
@Controller
@RequestMapping("/api/file")
public class ImageController {
    @Autowired
    private ImageService imageService;


    /**
     * 方法名: uploadAvatar
     * 描述: 上传头像
     *
     * @param image 头像图片
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/11/30 11:31
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/upload-avatar", method = RequestMethod.POST)
    @RequiresAuthentication
    @ResponseBody
    public ResultBean<Map<Object, Object>> uploadAvatar(@RequestParam("image") MultipartFile image) {
        return imageService.uploadAvatar(image);
    }

    /**
     * 方法名: uploadCarouselImg
     * 描述: 上传主页轮播图
     *
     * @param image 图片文件
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/11/30 11:50
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/upload-carouse-img", method = RequestMethod.POST)
    @RequiresAuthentication
    @ResponseBody
    @RequiresRoles("root")
    public ResultBean<Map<Object, Object>> uploadCarouselImg(@RequestParam("file") MultipartFile image) {
        return imageService.uploadCarouselImg(image);
    }
}
